package com.aust.state;

/**
 * 测试守护线程
 */
public class TestDeamon {
    public static void main(String[] args) {
        First first = new First();
        Second second = new Second();

        /**
         * 守护线程
         */
        Thread threadFirst = new Thread(first);
        /**
         * 默认：false
         * false：用户线程
         * true：守护线程
         */
        threadFirst.setDaemon(true);
        threadFirst.start();

        /**
         * 用户线程
         */
        Thread threadSecond = new Thread(second);
        threadSecond.start();

    }
}

/**
 * 老大
 */
class First implements Runnable {
    @Override
    public void run() {
        while (true) {
            System.out.println("老大保护老二！");
        }
    }
}

/**
 * 老二
 */
class Second implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 36500; i++) {
            System.out.println("活着");
        }
        System.out.println("goodbye world!");
    }
}